package org.aokey.springdemo3.July;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class InfoController {
    @RequestMapping("/A1/{num}")
    public String A1(@PathVariable String num){
        return "num:"+num;
    }
    @RequestMapping("/A2")
    public boolean A2(){
        return true;
    }
    //获取路径上的参数
    @RequestMapping("/A3/{name}/{id}")
    public String A3(@PathVariable String name, @PathVariable String id){
        return  "name:"+name+",id:"+id;
    }
    @RequestMapping("/A4/{n}")
    public String A4(@PathVariable("n") String name){
        return "name:"+name;
    }
    @RequestMapping("/A5")
    public String A5(@CookieValue("name")  String name){
        return "name:"+name;
    }
    @RequestMapping("/A6")
    public String A6(HttpServletRequest request){
        Cookie[] cookies=request.getCookies();
        for(Cookie cookie:cookies){
            System.out.println(cookie.getName()+":"+cookie.getValue());
        }
        return "name:"+request.getParameter("name");
    }
    @RequestMapping("/A7")
    public String A7(HttpServletResponse response){
        System.out.println(response.getHeader("Content-Type"));
        System.out.println(response.getHeader("user-agent"));
        System.out.println(response.getHeader("Cookie"));
        System.out.println(response.getHeader("hostname"));
        return "yes";
    }
    @RequestMapping("/A8")
    public String A8(@RequestBody  Map<Integer, Integer> map){
        map.forEach((k,v)->{
            System.out.println(k+":"+v);
        });
        return map.toString();
    }
}
